
/*
 *  ThunderCfg.h
 *
 *  
 *
 *  Create by Peter Liu < peter9882@gmail.com >
 *
 *  Modify by Peter Liu < peter9882@gmail.com >
 *  2010/03/04
 *
 */

#pragma once

#include "typedef.h"

#define URL_LEN             (1024)
#define TITLE_LEN           (256)
#define DESCRIPTION_LEN     (1024)
#define FILE_NAME_LEN       (1024)

#define CFG_BUFFER_LEN      (16*1024)
#define HEAD_BUFFER_LEN     (32*1024)
#define VIDEO_BUFFER_LEN    (2*1024*1024)

#define BLOCK_A_ITEM_BYTE   (36)
#define BLOCK_B_ITEM_BYTE   (20)

#define WM_UPDATEDATA   (WM_USER + 1999)

class CThunderCfg
{
public:
    CThunderCfg(void);
public:
    ~CThunderCfg(void);
public:
    ANSI_STRING * GetUrl(void);
public:
    ANSI_STRING * GetTitle(void);
public:
    ANSI_STRING * GetDescription(void);
public:
    bool OpenCfgFile(CString fileName);

private:
    ANSI_STRING strUrl[URL_LEN];
    ANSI_STRING strTitle[TITLE_LEN];
    ANSI_STRING strDescription[DESCRIPTION_LEN];
    CString strFileName;
    bool bCfgFileActive;

    U8 strCfgBuffer[CFG_BUFFER_LEN];
    U8 *strHeadBuffer;//[HEAD_BUFFER_LEN];
    U8 *strVideoBuffer;//[VIDEO_BUFFER_LEN];
    bool Parse(void);
private:
    U32 m_URL_Length;
private:
    U32 m_Title_Length;
private:
    U32 m_Description_Length;
private:
    U32 m_DateTime;
    U32 m_Encrypt_Length;

private:
    U32 m_Block_A_Count;
private:
    U32 m_Block_B_Count;

private:
    U32 m_Block_A_Offset;
private:
    U32 m_Block_B_Offset;
public:
    U32 GetBlockCount(void);
    U64 GetBlockStartAddr(unsigned int index);

private:
    typedef struct
    {
        U64 u64Addr;
        U64 u64Length;
        U32 u32Index;

        U32 u32Unknow1;
        U32 u32Unknow2;
        U32 u32Unknow3;
        U32 u32Unknow4;
    }ST_BLOCK_A;

    typedef struct
    {
        U64 u64Addr;
        U64 u64Length;
        U32 u32Flag;
    }ST_BLOCK_B;

    enum
    {
        ENCRYPT_METHOD_NONE = 0, 
        ENCRYPT_METHOD_1,
    };

public:
    U64 GetBlockLength(unsigned int index);
    U32 GetBlockFlag(unsigned int index);
public:
    bool Save(CString strSrcFolder, CString filename);
    bool Crack(unsigned char * buffer, unsigned int crackLen);
public:
    U32 GetEncryptMethod(unsigned char * buffer);
    U32 m_EncryptMethod;
    U8 m_CrackArg0;
public:
    U32 GetDateTime(void);
};
